<template>
  <div>
    <h2>名称：{{ name }}</h2>
    <h2>地址：{{ address }}</h2>
  </div>
</template>

<script>
import pubsub from 'pubsub-js'
export default {
  name: "Student",
  data() {
    return {
      name: "zhangsan",
      address: "china",
    };
  },
  mounted() {
   this.pubId =  pubsub.subscribe("hello",(msgname,data)=>{
      console.log('有人发布hello消息',msgname,data);
    })
  },
  beforeDestroy() {
    pubsub.unsubscribe(this.pubId);
  },
};
</script>

<style>
</style>